Plotly - We are making interactive plots

Create a flexdashboard using plotly for that includes at least three distinct plot types (e.g. scatterplots, line plots, bar plots, box plots, etc.)

data(rest_inspec)

NYC_food =
  rest_inspec |> 
  select(boro, score,cuisine_description, grade, zipcode) |> 
  drop_na(score) |> 
  drop_na(grade) |>
  mutate(boro = ifelse(boro == 'Missing', NA, boro)) |> 
  drop_na(boro) 

Make a scatterplot!

NYC_food |> 
  mutate(text_label = str_c("Grade: $", grade, "\nScore: ", score)) |> #\n: line break
  plot_ly(x = ~cuisine_description, y = ~score, color = ~zipcode, text = ~text_label,
          type = "scatter", mode = "markers") |>
  layout(
    title = "Scatter plot of scores by cuisine styles across zipcode",
    yaxis = list(title = "Scores"),
    xaxis = list(title = "Cuisine styles")
  )

Make a boxplot!

NYC_food |> 
  plot_ly(y = ~score, color = ~cuisine_description, 
          type = "box") |>
  layout(
    title = "Box plot of scores by cuisine styles",
    yaxis = list(title = "Scores"),
    xaxis = list(title = "Cuisine styles")
  )

Make a barplot!

NYC_food |>
  select(cuisine_description, boro) |>
  group_by(cuisine_description) |>
  summarise(n = n()) |>
  filter(n > 5000) |> 
  mutate(cuisine_description = ifelse(cuisine_description == "Latin (Cuban, Dominican, Puerto Rican, South & Central American)", "Latin",cuisine_description),
         cuisine_description = fct_reorder(cuisine_description, n)) |>
  plot_ly(x = ~cuisine_description, y = ~n, color = ~cuisine_description,
          type = "bar", colors = "viridis") |>
  layout(
    title = "Bar plot of number of cuisine styles",
    yaxis = list(title = "Number"),
    xaxis = list(title = "Cuisine Styles")
  )